package com.axsy.ddoo.func.record.adapter

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter4.BaseQuickAdapter
import com.mc.moring.R
import com.mc.moring.bean.MyTradeListBean
import com.mc.moring.main.MyTradesDetailsActivity
import com.mc.moring.util.StringUtils
import com.mc.moring.util.TimeUtils

class TradeHistoryAdapter(): BaseQuickAdapter<MyTradeListBean.dataBean, TradeHistoryAdapter.VH>(){

    class VH(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val tv_transTime: TextView = itemView.findViewById(R.id.tv_transTime)
        val tv_transAmount: TextView = itemView.findViewById(R.id.tv_transAmount)
        val tv_name: TextView = itemView.findViewById(R.id.tv_name)
        val tv_transType: TextView = itemView.findViewById(R.id.tv_transType)
        val tv_transStatus: TextView = itemView.findViewById(R.id.tv_transStatus)
        val ll: LinearLayout = itemView.findViewById(R.id.ll)
    }

    override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.item_my_trade, parent, false)
        return VH(view)
    }

    override fun onBindViewHolder(holder: VH, position: Int, item: MyTradeListBean.dataBean?) {

        item?:return

        holder.tv_transTime.text = TimeUtils.date2FormatDate(item.transTime)
        holder.tv_transAmount.text = "$${StringUtils.formatNumberWithCommas(item.transAmount)}"
        holder.tv_name.text = "$${StringUtils.formatNumberWithCommas(item.transAmount)}"

        Log.e("----item", item.toString())
        Log.e("----item.transNo", item.transNo)
        Log.e("----bean.getReqTransType()", item.reqTransType)
        Log.e("----bean.getSendAccount()", item.sendAccount)
        Log.e("----bean.getReceiveAccount()", item.receiveAccount)
        Log.e("----bean.getTransStatus()", item.transStatus)
        Log.e("----bean.getTransTime()", item.transTime)
        Log.e("----bean.getTransAmount()", item.transAmount)
        if (item.transStatus == "S") {
            holder.tv_transStatus.setText("Éxito")
        } else if (item.transStatus == "F") {
            holder.tv_transStatus.setText("Fracaso")
        } else {
            holder.tv_transStatus.setText("Procesando")
        }

        if (item.reqTransType == "OL") {
            holder.tv_transType.setText("Pago")
        } else if (item.reqTransType == "LA") {
            holder.tv_transType.setText("Préstamo")
        }


        holder.ll.setOnClickListener {

            val bundle = Bundle()
            bundle.putSerializable("_bean", item)
            val intent = Intent()
            intent.setClass(context, MyTradesDetailsActivity::class.java)
            intent.putExtras(bundle)
            context.startActivity(intent)
        }
    }


}